package com.travelms.controller;


import com.travelms.dao.DBFind;
import com.travelms.service.adminuserpage.AlterGoodsInfo;
import com.travelms.service.adminuserpage.DeleteUser;
import com.travelms.service.adminuserpage.ModifyAdminPsw;
import com.travelms.service.commonuserpage.publicchat.Client;
import com.travelms.util.DataEffect;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Scanner;
import java.util.Stack;

public class AdminUserPage {
    public static int adminPasswordStatus = 0;
    private DBFind dbFind = new DBFind();
    public AdminUserPage(String name) throws IOException, SQLException, InstantiationException, IllegalAccessException {
        //普通用户界面
        //用stack来表示层级结构以便更好返回上一级
        Stack<Integer> stack = new Stack<>();
        Scanner sc = new Scanner(System.in);
        String s;//中间效验输入是否为数字
        int current = 0;//记录当前目录层级
        stack.push(current);//初始化目录层级为0

        while (true){
            if (adminPasswordStatus == 1){
                break;
            }

            if (current == 0){ //主界面
                System.out.println("-----------------");
                System.out.println("管理员用户界面");
                System.out.println("1.修改商品信息");
                System.out.println("2.公共聊天");
                System.out.println("3.删除用户");
                System.out.println("4.修改管理员账户密码");
                System.out.println("5.退出登录");
                System.out.println("-----------------");
                while (true){
                    System.out.println("亲输入:");
                    s = sc.nextLine();
                    if (!DataEffect.isNumber(s)){//输入效验
                        System.out.println("输入错误");
                    } else if(!(s.compareTo("0") > 0 && s.compareTo("6") < 0)) {
                        System.out.println("输入错误");
                    }else {
                        current = Integer.parseInt(s);//记录输入的层级
                        stack.push(current);//压入栈
                        break;
                    }
                }
                if(current == 5){ //如果输入为8则退出
                    break;
                }



            }else if (current == 1){//为1时调用对应的界面或者是操作
                //修改商品信息
                new AlterGoodsInfo();
                stack.pop();
                current = stack.peek();

            } else if (current == 2){//为3时调用对应的界面或者是操作
                //公共聊天

                new Client("root");
                stack.pop();
                current = stack.peek();

            }else if (current == 3){//为3时调用对应的界面或者是操作
                new DeleteUser();
                stack.pop();
                current = stack.peek();


            }else if (current == 4){//为3时调用对应的界面或者是操作
                new ModifyAdminPsw();
                stack.pop();
                current = stack.peek();
            }







        }
    }

}
